Fix IntoPyArray for arrays of which the starting pointer is not equal…#194
Fix IntoPyArray for arrays of which the starting pointer is not equal…#194
Conversation
… to the pointer of the 1st element
| unsafe { PyArray::from_boxed_slice(py, dim, strides.as_ptr(), boxed) } | ||
| let (strides, dim) = (self.npy_strides(), self.raw_dim()); | ||
| let orig_ptr = self.as_ptr(); | ||
| let is_empty_or_size0 = self.is_empty() || std::mem::size_of::<Self>() == 0; |
There was a problem hiding this comment.
@kngwyu I think this size_of should be for the element, size_of::<A> (Self will never be size zero).
@jturner314 and me are maintainers of rust-ndarray and don't mind reviewing changes such as these, when we have time. I'm sorry that this use case is a bit tricky, due to missing low-level APIs - talking with us about what you need could be a good way to improve ndarray for the use cases.
There was a problem hiding this comment.
Thank you for your kind comments. I'll fix this later.
what you need could be a good way to improve ndarray for the use cases.
I guess @jturner314 already opened rust-ndarray/ndarray#994?
What we need is Box<[T]> and the pointer to the first element of the array. The pointer is used as void* data in https://numpy.org/doc/stable/reference/c-api/array.html#c.PyArray_NewFromDescr
Fix #182